<template>
  <div>
    <h1>展示搜索回来的数据</h1>
    <!-- 如果有数据展示数据，没有数据显示提示语请进行搜索 条件怎么写 items[]  false   items有值 true -->
    <h1 v-show="flag">请进行搜索</h1>
    <div v-show="!flag">
      <ListItem
        v-for="(item, index) in items"
        :key="index"
        :item="items[index]"
      ></ListItem>
    </div>
  </div>
</template>

<script>
import eventBus from "../utils/eventBus";
import ListItem from "./ListItem";
export default {
  name: "",
  props: [""],
  data() {
    return {
      items: [],
      flag: true
    };
  },

  components: {
    ListItem
  },

  computed: {},

  beforeMount() {},

  mounted() {
    eventBus.$on("sendMsg", async msg => {
      console.log(msg);
      //在里面发送ajax
      const url =
        "https://api.github.com/search/repositories?q=" + msg + "&sort=stars";
      const result = await this.$http.get(url);
      console.log(result);
      this.items = result.data.items;
      //当this.items中有数据  this.flag = false;
      this.flag = false;
    });
    // 发送ajax
  },

  methods: {},

  watch: {}
};
</script>
<style lang="" scoped></style>
